package myself.doit.schedule.v1;

import java.lang.reflect.Method;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

/**
 * Created by bjliuyong on 2017/1/10.
 */
public class SchedulerMain04 {

    public static void main(String args[]) throws Exception {

        SchedulerMain04 schedulerMain = new SchedulerMain04() ;
        Method method1 = schedulerMain.getClass().getMethod("echo1");
        Method method2 = schedulerMain.getClass().getMethod("echo2");


        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(20) ;


        new ReschedulingRunnable(executorService ,new ScheduledMethodRunnable(schedulerMain , method1) , "0/1 * * * * ?" ).schedule();
        new ReschedulingRunnable(executorService ,new ScheduledMethodRunnable(schedulerMain , method2) , "0/1 * * * * ?" ).schedule();

        Thread.sleep(5000L);
        executorService.shutdown();

    }


    public void echo1() {
        System.out.println("this is SchedulerMain03.echo1 " + CronSequenceGenerator.format(new Date()));
    }


    public void echo2() {
        System.out.println("this is SchedulerMain03.echo2 " + CronSequenceGenerator.format(new Date()));
    }

}
